<template>
  <XmSelect v-model="inputValue" :options="options" v-bind="{
    ...$attrs,
    placeholder: $attrs.placeholder || '请选择'
  }" v-on="$listeners"></XmSelect>
</template>

<script>
import inputValueMixin from '@/mixins/inputValueMixin'
import {
  getOptionTree,
} from "@/api/system/dict";
export default {
  name: 'CategorySelect',
  mixins: [inputValueMixin],
  props: {
    whileCodeList: {
      type: Array,
      default: () => []
    }
  },
  data() {
    return {
      options: [],
    };
  },
  methods: {
    getOptionTree() {
      getOptionTree({ code: 'added_service' }).then(res => {
        this.options = (res.data.data || []).map(item => {
          return {
            ...item,
            value: item.dictKey,
            label: item.dictValue,
          }
        })
        if (this.whileCodeList && this.whileCodeList.length) {
          this.options = this.options.filter(item => this.whileCodeList.includes(item.code))
        }
        this.$emit('afterLoaded', this.options)
      })
    }
  },
  created() {
    this.getOptionTree()
  }
};
</script>

<style scoped lang="scss">

</style>
